package com.tz.web;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.tz.bean.Course;
import com.tz.bean.TzParams;
import com.tz.service.course.ICourseService;

@Controller
@RequestMapping("/admin/course")
public class CourseController{

	@Autowired
	ICourseService courseService;
	
	@RequestMapping("/list")
	public String courseList(TzParams params){
		return "course/list";
	}
	
	@RequestMapping("/template")
	public ModelAndView template(TzParams params){
		ModelAndView modelAndView = new ModelAndView();
		params.setIsDelete(1);
		params.setStatus(1);
		List<Course> courses = courseService.listCourses(params);
		int count = courseService.count(params);
		modelAndView.setViewName("/course/template");
		modelAndView.addObject("courses",courses);
		modelAndView.addObject("count",count);
		return modelAndView;
	}
	
	@ResponseBody
	@RequestMapping(value="/delete",method=RequestMethod.POST)
	public String delete(TzParams params){
		courseService.delete(params);
		return "success";
	}
	
	@ResponseBody
	@RequestMapping(value="/update",method=RequestMethod.POST)
	public String update(Course course){
		courseService.update(course);
		return "success";
	}
}
